package com.autumn.web.auditing;

import javax.servlet.http.HttpServletRequest;

import com.autumn.auditing.ClientBrowserInfo;
import com.autumn.auditing.IClientBrowserInfo;
import com.autumn.auditing.IClientInfoProvider;
import com.autumn.util.WebUtils;

/**
 * Web 客户端信息提供者
 * 
 * @author 杨昌国
 *
 *         2017-10-20 12:02:45
 */
public class WebClientInfoProvider implements IClientInfoProvider {

	@Override
	public IClientBrowserInfo getBrowserInfo() {
		HttpServletRequest request = WebUtils.getCurrentRequest();
		if (request == null) {
			return ClientBrowserInfo.INSTANCE;
		}
		String value = request.getHeader("User-Agent");
		return new ClientBrowserInfo(value);
	}

	@Override
	public String getClientIpAddress() {
		return WebUtils.getCurrentRequestAddress();
	}

	@Override
	public String getClientPlatformVersion() {
		HttpServletRequest request = WebUtils.getCurrentRequest();
		if (request == null) {
			return "";
		}
		String value = request.getHeader("client-platform-version");
		if (!WebUtils.isInvalidWebString(value)) {
			return value;
		}
		return "";
	}

	@Override
	public String getClientPlatformName() {
		HttpServletRequest request = WebUtils.getCurrentRequest();
		if (request == null) {
			return "";
		}
		String value = request.getHeader("client-platform-name");
		if (!WebUtils.isInvalidWebString(value)) {
			return value;
		}
		return "";
	}
}
